<?php



defined('BASEPATH') OR exit('No direct script access allowed');

include 'linkdatabase.php';
include 'findInDatabase.php';


class Sinput extends CI_Controller {
  public function index(){
	  $sellername=$_GET['sellername'];
	  $schoolId=$_GET['schoolId'];
	  $partId=$_GET['partId'];
	  $jobname=$_GET['jobname'];
	  $jobadress=$_GET['jobadress'];
	  $jobdetail=$_GET['jobdetail'];
	  $time=$_GET['time'];
	  $price=$_GET['price'];
	  $contect=$_GET['contect'];
		$contectId=$_GET['contectId'];
		$openId=$_GET['openId'];
		$date=date("Y-m-d");
    $status="确认完成";

    $link = linkdatabase::link();
    @mysqli_select_db($link, "witkey");

		$uid=findInDatabase::finduid($openId);
		if($uid==null){
			$qury="INSERT INTO users (`u_id`,`open_id`,`name`,`contact`,`contactId`) VALUES (null,'$openId','$sellername','$contect',      '$contectId')";
		  $res = mysqli_query($link, $qury);
			$uid=findInDatabase::finduid($openId);
      if (!$res) {
        echo $res;
        echo 'can not run1';
      }
		}else{
      $qury="UPDATE users SET `name`='$sellername',`contact`='$contect',`contactId`='$contectId' WHERE `open_id`='$openId'";
		}

    $sql="INSERT INTO mission (`m_id`, `m_name`, `m_expression`, `m_pay`, `m_place`, `m_time`, `district`, `category`, `m_state`, `m_date`,`u_id`) VALUES (null,'$jobname','$jobdetail','$price','$jobadress','$time','$schoolId','$partId','$status','$date','$uid')";
    $result = mysqli_query($link, $sql);
      if (!$result) {
        echo $result;
            echo 'can not run2';
      }else{
				$data="success";
				header(	'Content-Type:text/json');
				echo json_encode($data);
			}

  }
}